home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_06 / 2n06076b < prev    next >
Text File  |  1991-04-14  |  561b  |  23 lines

  1.  
  2.      double setsigdig(double x, unsigned int n)
  3.          {
  4.          double shift, result;
  5.      
  6.          if ((n == 0U) || (n > DBL_DIG))
  7.              result = x;
  8.          else
  9.              {
  10.              // adjust the number of significant digits
  11.              --n;
  12.      
  13.              // calculate the number of digits to be shifted
  14.              shift = pow(10.0,(double)n 
  15.                         - floor(log10(fabs(x))));
  16.      
  17.              result = tonearest(x * shift) / shift;
  18.              }
  19.      
  20.          return result;
  21.          }
  22.  
  23.